package com.scedu.controller;

import com.scedu.entity.User;
import com.scedu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.jws.soap.SOAPBinding;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/findall")
    public ModelAndView findAll(Map<String,Object> map){
        List<User> userList=  userService.findAll();
        map.put("userList", userList);
        return new ModelAndView("showAll", map);
    }

    @GetMapping("/save")
    public  ModelAndView save(User user){
        userService.save(user);
        String url = "redirect:http://localhost:8900/sc/user/findall";
        return new ModelAndView(url);
    }
}
